<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test.js"></script>
</head>
<body>
<script>
description('Test for validationMessage IDL attribute for &lt;input type=date>');
var parent = document.createElement('div');
document.body.appendChild(parent);
parent.innerHTML = '<input type=date id=date maxlength=1 pattern=x>';
var input = document.getElementById('date');
input.offsetLeft;

function testIt(value, min, max, step)
{
    input.setAttribute("max", max);
    input.setAttribute("min", min);
    input.setAttribute("step", step);
    input.setAttribute("value", value);
    return input.validationMessage;
}

debug('No message')
shouldBeEqualToString('testIt("", "", "")', '');

debug('Value missing')
input.setAttribute("required", "");
shouldBeEqualToString('testIt("", "", "")', 'Please fill out this field.');
input.removeAttribute("required");

debug('Type mismatch');
shouldBeEqualToString('testIt("foo", "", "")', '');

debug('Range invalid')
shouldBeEqualToString('testIt("1990-05-29", "1990-05-30", "1990-05-28")', 'Minimum date (05/30/1990) must come before Maximum date (05/28/1990).');

debug('Range overflow')
shouldBeEqualToString('testIt("1982-11-02", "", "1970-12-31")', 'Value must be 12/31/1970 or earlier.');

debug('Range underflow')
shouldBeEqualToString('testIt("1982-11-02", "1990-05-25", "1990-12-24")', 'Value must be 05/25/1990 or later.');

debug('Step mismatch')
shouldBeEqualToString('testIt("1982-11-02", "1982-01-01", "", "123")', 'Please enter a valid value. The two nearest valid values are 09/04/1982 and 01/05/1983.');

</script>
</body>
</html>
